<template>
  <div class="scaleDialog">
    <basic-container>
      <avue-crud
        :option="option"
        :data="data"
        v-model="item"
        @on-load="onLoad"
        @selection-change="selectionChange"
        :search.sync="search"
        @refresh-change="onLoad"
      >
        <template slot="menuLeft" slot-scope="{ size }">
          <el-button
            type="primary"
            size="small"
            icon="el-icon-plus"
            @click="submitInfo"
            >添加绑定年级</el-button
          >
          <el-button size="small" icon="" @click="cancelDialog">取消</el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { addProjectinclude, getList } from "@/api/census/grade";
export default {
  name: "scaleDialog",
  // components: { QuestionPreview },
  data() {
    return {
      item: {},
      questionPreviewVisible: false,
      search: {},
      gaugeId: "",
      selectionList: [],
      promote: true,
      page: {
        pageSize: 10,
      },
      option: {
        addBtn: false,
        excelBtn: false,
        selectClearBtn: false,
        delBtn: false,
        border: true,
        index: true,
        columnBtn: false,
        searchShowBtn: false,
        selection: true,
        editBtn: false,
        expandLevel: 3,
        headerAlign: "left",
        align: "left",
        tree: false,
        maxHeight: 200,
        labelWidth: 100,
        menuWidth: 100,
        menu: false,
        column: [
          {
            label: "年级",
            prop: "gradeName",
            search: false,
          },
        ],
      },
      data: [],
      query: {},
    };
  },
  methods: {
    async onLoad(page, params = {}) {
      const {
        data: { data },
      } = await getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      );
      this.data = data;
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    cancelDialog() {
      this.$emit("close");
    },
    submitInfo() {
      let projectId = this.$route.query.projectId;
      let list = [];
      for (let i = 0; i < this.selectionList.length; i++) {
        let rowData = this.selectionList[i];
        list.push({
          projectId: projectId,
          includeName: rowData.gradeName,
          includeId: rowData.id,
        });
      }
      let schoolparams = {};
      schoolparams.projectId = projectId;
      schoolparams.projectIncludeEntityList = list;

      addProjectinclude(schoolparams).then(() => {
        this.$emit("onloadInfo");
        this.$emit("close");
        this.$message({
          type: "success",
          message: "操作成功!",
        });
      });
    },
    handlePreview(row) {
      this.gaugeId = row.gaugeId;
      this.questionPreviewVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.scaleDialog {
}
</style>
